#import <Foundation/Foundation.h>
#import "FXEnum.h"
#import "DmUtil.h"
#import "OFDViewControl.h"

@protocol IDvDocViewer;
@protocol IDvPageView;
@protocol IDvPageScrollView;
@class DmDocument;
@class DvCache;

// IDvPageEventListener
@protocol IDvPageEventListener <NSObject>
- (void)onPageVisible:(int)index;
- (void)onpageInvisible:(int)index;
- (void)onPageChanged:(int)oldIndex currentIndex:(int)currentIndex;
@end

// IDvTouchEventListener
@protocol IDvTouchEventListener <NSObject>
@optional
- (void)onUserInteraction;
- (BOOL)onTap:(id<IDvDocViewer>)dviewer recognizer:(UITapGestureRecognizer *)recognizer;
- (BOOL)onLongPress:(id<IDvDocViewer>)dviewer recognizer:(UILongPressGestureRecognizer *)recognizer;

- (void)onScrollViewWillBeginDragging:(id<IDvDocViewer>)dviewer;
- (void)onScrollViewDidEndDragging:(id<IDvDocViewer>)dviewer willDecelerate:(BOOL)decelerate;
- (void)onScrollViewWillBeginDecelerating:(id<IDvDocViewer>)dviewer;
- (void)onScrollViewDidEndDecelerating:(id<IDvDocViewer>)dviewer;

- (void)onScrollViewWillBeginZooming:(id<IDvDocViewer>)dviewer;
- (void)onScrollViewDidEndZooming:(id<IDvDocViewer>)dviewer;
@end

// IDvDrawEventListener
@protocol IDvDrawEventListener <NSObject>
- (void)onDocViewerDraw:(id<IDvDocViewer>)dviewer inContext:(CGContextRef)context;
- (void)onDrawPageView:(id<IDvPageView>)pageView inContext:(CGContextRef)context;
@end

// IDvJumpEventListener
@protocol IDvJumpEventListener <NSObject>
- (void)onPageJumped;
@end

@protocol IUserInteractionListener <NSObject>
@optional
- (void)onUserInteraction;
@end

@interface DvReadingStatus : NSObject
@property (nonatomic,assign) PDF_LAYOUT_MODE    displayMode;
@property (nonatomic,assign) BOOL   showImage;
@property (nonatomic,assign) int    pageIndex;
@property (nonatomic,assign) float  scale;
// (x, y) is the point on document page coordinate
// which is mapping from docviewer to pdf page
@property (nonatomic,assign) float  x;
@property (nonatomic,assign) float  y;
@end

// IDvDocViewer
@protocol IDvDocViewer <NSObject>

- (BOOL)load;
- (UIView*)getRootView;
//- (void)showMenu:(MenuControl*)menu;
//- (void)hideMenu:(MenuControl*)menu;
- (void)setIsNightMode:(BOOL)isNight;
- (void)setBackgroundColor:(UIColor*)color;

- (BOOL)setDocument:(DmDocument*)document readingStatus:(DvReadingStatus*)readingStatus;
- (DmDocument*)getDocument;
- (int)getCurrentPage;
- (DvReadingStatus*)getReadingStatus;

- (void)changeDisplayMode:(PDF_LAYOUT_MODE)mode;
- (PDF_LAYOUT_MODE)getPageLayoutMode;
- (PDF_LAYOUT_MODE)getPreviousDisplayMode;

- (int)bottomOffset;
- (void)setBottomOffset:(int)offset;

- (BOOL)scrollDirectionalLocked;
- (void)setScrollDirectionalLocked:(BOOL)locked;
- (BOOL)scrollDisabled;
- (void)setScrollDisabled:(BOOL)disabled;
- (BOOL)zoomLocked;
- (void)setZoomLocked:(BOOL)locked;
- (BOOL)screenLocked;
- (void)setScreenLocked:(BOOL)locked;
- (BOOL)doulbeTapDisabled;
- (void)setDoubleTapDisabled:(BOOL)disabled;

- (id<IDvPageView>)getPageView:(int)index;
-  (NSString*)getDisplayPageLabel:(int)pageIndex needTotal:(BOOL)needTotal;
- (void)resizeAllPageViews; //for crop

- (void)gotoPage:(int)index animated:(BOOL)animated;
- (void)gotoPage:(int)index withDocPoint:(FSPointF*)point animated:(BOOL)animated;
- (void)gotoPage:(int)index withDevPoint:(CGPoint)point animated:(BOOL)animated;

- (BOOL)hasPrevView;
- (BOOL)hasNextView;
- (void)gotoPrevView:(BOOL)animated;
- (void)gotoNextView:(BOOL)animated;

- (void)gotoPreviousPageWithAnimated:(BOOL)animated;
- (void)gotoNextPageWithAnimated:(BOOL)animated;

- (BOOL)isMaxZoomScale;
- (BOOL)isMinZoomScale;

- (CGPoint)convertPdfPtToPageViewPt:(FSPointF*)point pageIndex:(int)index;
- (CGRect)convertPdfRectToPageViewRect:(FSRectF *)rect pageIndex:(int)index;
- (FSPointF*)convertPageViewPtToPdfPt:(CGPoint)point pageIndex:(int)index;
- (FSRectF *)convertPageViewRectToPdfRect:(CGRect)rect pageIndex:(int)index;
- (CGPoint)pageViewToDocViewerPoint:(CGPoint)point pageIndex:(int)index;
- (CGRect)convertPageViewRectToDisplayViewRect:(CGRect)rect pageIndex:(int)index;
- (CGPoint)convertDisplayViewPtToPageViewPt:(CGPoint)point pageIndex:(int)index;
- (CGRect)convertDisplayViewRectToPageViewRect:(CGRect)rect pageIndex:(int)index;

- (void)invalidate:(CGRect)rect;

- (void)onWillRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)onWillAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)onDidRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

- (void)registerPageEventListener:(id<IDvPageEventListener>)listener;
- (void)unregisterPageEventListener:(id<IDvPageEventListener>)listener;

- (void)registerTouchEventListener:(id<IDvTouchEventListener>)listener;
- (void)unregisterTouchEventListener:(id<IDvTouchEventListener>)listener;

- (void)registerDrawEventListener:(id<IDvDrawEventListener>)listener;
- (void)unregisterDrawEventListener:(id<IDvDrawEventListener>)listener;

- (void)registerJumpEventListener:(id<IDvJumpEventListener>)listener;
- (void)unregisterJumpEventListener:(id<IDvJumpEventListener>)listener;

- (id<IDvPageScrollView>)createPageScrollViewWithFrame:(CGRect)rect pageIndex:(int)pageIndex;
- (UIView*)createFileCompareView:(NSArray*)docs withFrame:(CGRect)rect;

- (void)onPageVisible:(int)index;
- (void)onPageInVisible:(int)index;

@end

@interface DvFactory : NSObject
+ (id<IDvDocViewer>)createDocViewer;
@end

